<%@ page language="java" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>盈利情况查询</title>
<%@ include file="/WEB-INF/pages/common/frameCommonJs.jsp"  %>
<script>
   var getClassUrl = "<%=request.getContextPath()%>/product/getAllPoductClassJson.action";
   $(function(){
	   $('.icon-reload').click(
				function (){ 
					$('#ocTree').tree({url:'<%=request.getContextPath()%>/product/getAllPoductClassJson.action'});
					$('#ocTree').tree('reload')
				}
			);
			$(".icon-reload").css("cursor","pointer");
			
		$('#ocTree').tree({
			animate: true,
			url: getClassUrl,
			onBeforeExpand:function(node){
				$('#ocTree').tree("options").url=getClassUrl + "?pc.id=" + node.id;
			},
			onClick:function(node){
				var node = $('#ocTree').tree('getSelected');
				$('#orgs').datagrid('reload',{'pcId':node.id});
				$('#orgs').datagrid({pageNumber:1});
				$('#pcId').val(node.id);
				$('#ocTree').tree('expand',node.target);
			},
			onContextMenu: function(e, node){
				e.preventDefault();
				$('#ocTree').tree('select', node.target);
				$('#mm').menu('show', {
					left: e.pageX,
					top: e.pageY
				});
			}
			
		})
		// 右侧表单内容
		$('#orgs').datagrid({
				fit:true,
				nowrap: false,
				striped: true,
				collapsible:true,
				url:'<%=request.getContextPath()%>/searchcenter/searchProfit.action',
				sortName: 'code',
				sortOrder: 'desc',
				remoteSort: false,
				idField:'code',
				singleSelect:true,
				title:'统计结果',
				columns:[[
					{field:'proNo',title:'商品编号',width:120},
					{field:'proName',title:'商品名称',width:200},
					{field:'proClassName',title:'商品类别',width:100},
					{field:'proSpec',title:'商品规格',width:120},
					{field:'saleNum',title:'销售数量',width:150,align:'right'},
					/* {field:'unit',title:'单位',width:150}, */
					{field:'avgCost',title:'成本均价(元)',width:150,align:'right',
						formatter:function(value,row,index){
							return row.avgCost.toFixed(2);
						},sortable:true
					},
					{field:'costPrice',title:'成本金额(元)',width:150,align:'right',
						formatter:function(value,row,index){
							return row.costPrice.toFixed(2);
						},sortable:true
					},
					{field:'avgSalePrice',title:'销售均价(元)',width:150,align:'right',
						formatter:function(value,row,index){
							return row.avgSalePrice.toFixed(2);
						},sortable:true
					},
					{field:'salePrice',title:'销售金额(元)',width:150,align:'right',
						formatter:function(value,row,index){
							return row.salePrice.toFixed(2);
						},sortable:true
					},
					{field:'profitPrice',title:'盈利金额(元)',width:150,align:'right',
						formatter:function(value,row,index){
							return row.profitPrice.toFixed(2);
						},sortable:true
					}
				]],
				pageSize:15,  
                pageList:[5,10,15,20],  
                fitColumns: true,  
				pagination:true,
				rownumbers:true
		})
   });
   function searchVoucher(){
		var node = $('#ocTree').tree('getSelected');
		var pcId;
		if(node!=null){
			pcId = node.id;
		}
		var searchProName = $("#searchProName").val();
		if($.trim(searchProName) != ""){
			pcId = "";
		}
		var stime = $("input[name=stime]").val();
   		var etime = $("input[name=etime]").val();
   		$("#sshowtime").html("<b>" + stime + "</b>");
   		$("#eshowtime").html("<b>" + etime + "</b>");
		$('#orgs').datagrid('reload',{'searchVoucherCondition.pcId':pcId,'searchVoucherCondition.stime':stime,'searchVoucherCondition.etime':etime,'searchVoucherCondition.searchProName':searchProName});
		$('#orgs').datagrid({pageNumber:1});
	}
	
	function searchClear(){
		location.reload()
	}
	
	function exportProfit(){ 
		getClassUrl = "<%=request.getContextPath()%>/searchcenter/exportProfit.action";
	    $('#searchForm').form('submit',{  
	        url:getClassUrl,  
	        onSubmit: function(){  
	        	var stime = $("#stime").val();
	        	var etime = $("#etime").val();
	        	var searchProName = $("#searchProName").val();
	        	var pcId = $("#pcId").val();
	            return $(this).form('validate');  
	        },  
	        success: function(result){  
	            var result = eval('('+result+')');
	            if (result==true){
	            	$.messager.show({title:"提示信息:", msg:"导出成功！"});
	            } else {  
	                $.messager.show({title:"提示信息:", msg:"导出失败！"});  
	            }  
	        }  
	    });  
	}
</script>
</head>
<body class="easyui-layout" >
<div region="west" iconCls="icon-reload" title="商品分类" split="true" style="width:180px;">
		<ul id="ocTree"></ul>
</div>
<div region="center" title="盈利情况" style="overflow:auto;" split="true">
	<div class="easyui-layout" data-options="fit:true">
		<div style="height:130px" data-options="region:'north',border:false">
			<div id="tb" class="datagrid-toolbar">  
			    <a href="#" class="easyui-linkbutton" iconCls="icon-search" plain="true" onclick="javascript:searchVoucher()">查询</a>  
			    <a href="#" class="easyui-linkbutton" iconCls="icon-reload" plain="true" onclick="javascript:searchClear()">重置</a>  
			    <a href="#" class="easyui-linkbutton" iconCls="icon-excel" plain="true" onclick="javascript:exportProfit()">导出</a>
			</div>
			<center>
			<form id="searchForm" method="post">
			<table style="font-size:12px;padding:10px;" border="0">
				<input type="hidden" id="pcId" name="pcId" value="" />
				<tr>
					<td>
						商品名称 
					</td>
					<td align="left">
						<input type="text" name="searchProName" id="searchProName" title="查询所有商品" value="" />
					</td>
				</tr>
				<tr>
					<td align="right">
						统计日期
					</td>
					<td>
						<input class="easyui-datebox" name="stime" id="stime" style="width:100px" readonly="readonly" /> ~ <input class="easyui-datebox" name="etime" id="etime" style="width:100px" readonly="readonly" />
					</td>
				</tr>
			</table>
			</form>
			</center>
		</div>
		<div data-options="region:'center',border:false">
			<table id="orgs"></table>
		</div>
	</div>
</div>
</div>
</body>
</html>